<!--
 * @Author: Bonnie
 * @Date: 2021-12-23 16:08:42
 * @LastEditTime: 2021-12-23 16:17:07
 * @LastEditors: Bonnie
 * @Description: 空值合并运算符 与 或运算
 * @FilePath: /public_demo/src/views/JsSkill/page4.vue
-->
<template>
  <div>
    <h2>|| 或运算演示</h2>
    <p>逻辑或操作符会在左侧操作数为 <strong> 假值('',0,null,undefined)</strong> 时返回右侧操作数。</p>
    <article>
      <pre>
            <code>
let a = '', b = 0, c = null, d = undefined;
let res = a || b || c || d || '都不匹配'
console.log(res); // '都不匹配'
            </code>
        </pre>
    </article>
    <h2 class="mt20">??空值合并运算符演示</h2>
    <p>当左侧的操作数为<strong> null 或者 undefined </strong>时，返回其右侧操作数，否则返回左侧操作数。</p>
    <article>
      <pre>
            <code>
let a = '', b = 0, c = null, d = undefined;
let res1 = a ?? '都不匹配';
let res2 = b ?? '都不匹配';
let res3 = c ?? '都不匹配';
let res4 = d ?? '都不匹配';
console.log(a) // 0
console.log(b) // ''
console.log(c) // '都不匹配'
console.log(d) // '都不匹配'
 
            </code>
        </pre>
    </article>
  </div>
</template>
<script>
export default {
  name: "page4",
  data() {
    return {};
  }
};
</script>
<style lang='scss' scoped>
</style>